/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.scene.service.impl;


import com.koron.scene.domain.ProjectCertificate;
import com.koron.scene.mapper.ProjectCertificateMapper;
import org.koron.ebs.mybatis.SessionFactory;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class ProjectCertificateJob implements Job {

    private static final Logger logger = LoggerFactory.getLogger(ProjectCertificateJob.class);

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        SessionFactory factory = new SessionFactory();
        try {
            ProjectCertificateMapper mapper = factory.getMapper(ProjectCertificateMapper.class);
            List<ProjectCertificate> projectCertificateList = mapper.findNewExpired();
            if (projectCertificateList != null) {
                ProjectCertificate up = new ProjectCertificate();
                up.setState(1);
                for (ProjectCertificate p : projectCertificateList) {
                    up.setId(p.getId());
                    mapper.updateByPrimaryKeySelective(up);
                }
            }
        } catch (Exception e) {
            logger.error("查询即将过期的相关方证照发生异常" + e.getMessage());
            factory.close(false);
        } finally {
            if (factory != null) {
                factory.close();
            }
        }
    }
}
